<template>
	<view class="content">
		扫描结果：{{input}}
		<button type="default" @click="scanCode()">扫描</button>
		<xw-scan></xw-scan>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			input:''
			}
		},
		onLoad() {

		},
		onUnload() {
		   // 移除监听事件      
		   uni.$off('xwscan')
		},
		onShow() {
			let that = this
			uni.$off('xwscan') // 每次进来先 移除全局自定义事件监听器
			uni.$on('xwscan', (res)=> {
				console.log('扫码结果：', res.code);
				this.input = res.code
			})
		},
		methods: {
		scanCode() {
			uni.scanCode({
				onlyFromCamera: true,
				success: (res) => {
					console.log('条码类型：' + res.scanType);
					console.log('条码内容：' + res.result);
					this.input = res.result
					// that.$forceUpdate()
				}
			});
		},
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
